package com.ja.openchat.ui.chat.group;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.google.gson.JsonObject;
import com.ja.openchat.AppViewModelFactory;
import com.ja.openchat.BR;
import com.ja.openchat.BuildConfig;
import com.ja.openchat.R;
import com.ja.openchat.databinding.ActivityContactChatMediaBinding;
import com.ja.openchat.databinding.ActivityGroupChatMediaBinding;
import com.ja.openchat.ui.contact.ContactDetailChildFragment;
import com.ja.openchat.ui.contact.OnContactChatInfoListener;
import com.ja.openchat.ui.message.adapter.SimpleFragmentPagerAdapter;
import com.ja.openchat.viewmodels.ContactDetailSingleViewModel;
import com.ja.openchat.viewmodels.GroupChatSettingSingleViewModel;
import com.zy.openchat.core.manager.TelegramManager;
import com.zy.openchat.core.manager.TgResultBlock;
import com.zy.openchat.core.model.message.ChatInfo;
import com.zy.openchat.core.model.user.UserFullInfo;
import com.zy.openchat.core.model.user.UserInfo;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProviders;
import me.goldze.mvvmhabit.base.BaseActivity;

public class GroupChatMediaActivity extends BaseActivity<ActivityGroupChatMediaBinding, GroupChatSettingSingleViewModel> {

    public ChatInfo chatInfo;


    public static void start(Activity activity, ChatInfo chat) {
        Intent intent = new Intent();
        intent.setClass(activity, GroupChatMediaActivity.class);
        intent.putExtra("chat", chat);
        activity.startActivity(intent);
    }

    @Override
    public GroupChatSettingSingleViewModel initViewModel() {
        //使用自定义的ViewModelFactory来创建ViewModel，如果不重写该方法，则默认会调用LoginViewModel(@NonNull Application application)构造方法
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, factory).get(GroupChatSettingSingleViewModel.class);
    }

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_group_chat_media;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }


    @Override
    public void initView() {
        super.initView();
//        setTitle(getString(R.string.chat_record));

        binding.toolbar.ivBarBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        if (getIntent() != null) {
            chatInfo = getIntent().getParcelableExtra("chat");
        } else {
            chatInfo = new ChatInfo();
        }
        List<Fragment> fragments = new ArrayList<>();
        SimpleFragmentPagerAdapter fragmentAdater = null;

        if(BuildConfig.ShowLocal_ChatRecord){
            fragments.add(GroupSettingChildFragment.newInstance(0, chatInfo));
            fragments.add(GroupSettingChildFragment.newInstance(1, chatInfo));
            fragments.add(GroupSettingChildFragment.newInstance(2, chatInfo));
            fragments.add(GroupSettingChildFragment.newInstance(3, chatInfo));
            fragments.add(GroupSettingChildFragment.newInstance(4, chatInfo));
            fragments.add(GroupSettingChildFragment.newInstance(5, chatInfo));
            fragmentAdater = new SimpleFragmentPagerAdapter(getSupportFragmentManager(), fragments
                    , new String[]{getString(R.string.member_text), getString(R.string.media_text), getString(R.string.file_text), getString(R.string.voice_text), getString(R.string.link_text), "GIF"});
        }else{
            fragments.add(GroupSettingChildFragment.newInstance(0, chatInfo));

            fragmentAdater = new SimpleFragmentPagerAdapter(getSupportFragmentManager(), fragments
                    , new String[]{getString(R.string.member_text)});
        }
        binding.viewPager.setAdapter(fragmentAdater);
        binding.viewPager.setOffscreenPageLimit(fragments.size());
        binding.tablayout.setupWithViewPager(binding.viewPager);

    }


}